Completed
Pull Request — future (#197)
by Xaver
38s
created

legend.js ➔ ... ➔ d.nodes.online.map   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
1
define(['helper'], function (helper) {
2
  'use strict';
3
4
  return function (config, language) {
5
    var self = this;
6
    var stats = document.createTextNode('');
7
    var timestamp = document.createTextNode('');
8
9
    self.setData = function setData(d) {
10
      var totalNodes = Object.keys(d.nodeDict).length;
11
      var totalOnlineNodes = d.nodes.online.length;
12
      var totalClients = helper.sum(d.nodes.online.map(function (n) {
13
        return n.clients;
14
      }));
15
      var totalGateways = helper.sum(d.nodes.online.filter(function (n) {
16
        return n.is_gateway;
17
      }).map(helper.one));
18
19
      stats.textContent = _.t('sidebar.nodes', { total: totalNodes, online: totalOnlineNodes }) + ' ' +
20
        _.t('sidebar.clients', { smart_count: totalClients }) + ' ' +
21
        _.t('sidebar.gateway', { smart_count: totalGateways });
22
23
      timestamp.textContent = _.t('sidebar.lastUpdate') + ' ' + d.timestamp.fromNow();
24
    };
25
26
    self.render = function render(el) {
27
      var h1 = document.createElement('h1');
28
      h1.textContent = config.siteName;
29
      el.appendChild(h1);
30
31
      language.languageSelect(el);
32
33
      var p = document.createElement('p');
34
      p.classList.add('legend');
35
36
      p.appendChild(stats);
37
      p.appendChild(document.createElement('br'));
38
      p.appendChild(timestamp);
39
      el.appendChild(p);
40
    };
41
42
    return self;
43
  };
44
});
45